package de.szut.bomberman.gui.mainmenu;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.HashMap;

import de.szut.bomberman.gui.game.GamePanel;
import de.szut.bomberman.gui.info.InfoPanel;
import de.szut.bomberman.gui.main.DefaultPanel;
import de.szut.bomberman.gui.options.OptionsPanel;
import de.szut.bomberman.main.Controller;
import de.szut.bomberman.main.GameMode;
import de.szut.gui.language.Languages;
import de.szut.gui.language.TranslatableComponent;
import de.szut.gui.language.TranslatableHoverLabel;

public class MainMenuPanel extends DefaultPanel {
	public static final int BUTTONWIDTH = 400;
	public static final int BUTTONHEIGHT = 30;
	public static final int STARTPOSITIONY = 150;
	public static final int STARTPOSITIONX = Controller.getInstance().getGuiController().getMainFrame().getWidth()/2-BUTTONWIDTH/2+5;
	public static final int OFFSETY = 50;
	public static final ArrayList<String> SELECTIONBUTTONS = new ArrayList<String>();
	static {
		SELECTIONBUTTONS.add("playervsplayer");
		SELECTIONBUTTONS.add("playervsai");
		SELECTIONBUTTONS.add("options");
		SELECTIONBUTTONS.add("info");
	}
	
	private static final long serialVersionUID = 1L;
	
	private ArrayList<TranslatableComponent> translatableComponents;
	private HashMap<String,TranslatableHoverLabel> selectionButtons;

	public MainMenuPanel() {
		// TODO: Style MainMenuPanel
		translatableComponents = new ArrayList<TranslatableComponent>();
		selectionButtons = new HashMap<String,TranslatableHoverLabel>();
		
		Languages.prepareComponent("mainmenu.MainMenuPanel.header", getHeader(), translatableComponents);
		Languages.prepareComponent("mainmenu.MainMenuPanel.exit", getReturnButton(), translatableComponents);
		getReturnButton().addMouseListener(new MouseAdapter() {
			
			@Override
			public void mouseClicked(MouseEvent arg0) {
				Controller.getInstance().getGuiController().getMainFrame().dispose();
			}
		});
		
		int currentYPos = STARTPOSITIONY;
		
		for (String currentSelectionKey : SELECTIONBUTTONS) {
			TranslatableHoverLabel currentButton = new TranslatableHoverLabel();
			selectionButtons.put(currentSelectionKey, currentButton);
			Languages.prepareComponent("mainmenu.MainMenuPanel." + currentSelectionKey.toLowerCase(), currentButton, translatableComponents);
			currentButton.setBounds(STARTPOSITIONX, currentYPos, BUTTONWIDTH, BUTTONHEIGHT);
			add(currentButton);
			currentYPos += OFFSETY;
		}
		
		selectionButtons.get("playervsplayer").addMouseListener(new MouseAdapter() {
			
			@Override
			public void mouseClicked(MouseEvent arg0) {
				Controller.getInstance().getGuiController().switchPanel(new GamePanel(GameMode.PLAYERVSPLAYER));
			}
		});
		
		selectionButtons.get("playervsai").addMouseListener(new MouseAdapter() {
			
			@Override
			public void mouseClicked(MouseEvent arg0) {
				Controller.getInstance().getGuiController().switchPanel(new GamePanel(GameMode.PLAYERVSCOMPUTER));
			}
		});
		
		selectionButtons.get("options").addMouseListener(new MouseAdapter() {
			
			@Override
			public void mouseClicked(MouseEvent arg0) {
				Controller.getInstance().getGuiController().switchPanel(new OptionsPanel());
			}
		});
		
		selectionButtons.get("info").addMouseListener(new MouseAdapter() {
			
			@Override
			public void mouseClicked(MouseEvent arg0) {
				Controller.getInstance().getGuiController().switchPanel(new InfoPanel());
			}
		});
		
		Controller.getInstance().getGuiController().getLanguages().translateListOfComponents(translatableComponents);
	}
}
